package cn.south.campus.business.service.impl;

import cn.south.campus.business.mapper.AdMapper;
import cn.south.campus.business.model.entity.Ad;
import cn.south.campus.business.model.vo.AdVo;
import cn.south.campus.business.service.AdService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/12/27 11:30
 */
@Service
public class AdServiceImpl extends ServiceImpl<AdMapper, Ad> implements AdService {
    @Resource
    private AdMapper adMapper;

    @Override
    public List<AdVo> getByPos(List<String> posNoList) {
        Date now = new Date();
        LambdaQueryWrapper<Ad> wrapper = new LambdaQueryWrapper<Ad>()
                .in(Ad::getPosNo, posNoList)
                .le(Ad::getStartTime, now)
                .ge(Ad::getEndTime, now);
        List<Ad> adList = adMapper.selectList(wrapper);
        if (CollectionUtils.isEmpty(adList)) {
            return null;
        }
        return adList.stream().map(AdVo::convert).collect(Collectors.toList());
    }
}
